﻿using System.Threading.Tasks;
using TabbedTemplate.Views;
using Xamarin.Forms;

namespace TabbedTemplate.Services
{
    public class AlertService : IAlertService
    {
        // ******** 私有变量
        //Application.Current.MainPage返回的类型是Page
        private MainPage MainPage => (MainPage)Application.Current.MainPage;
        // ******** 继承方法

        /// <summary>
        /// 显示警告。
        /// </summary>
        /// <param name="title">标题。</param>
        /// <param name="message">信息。</param>
        /// <param name="button">按钮文字。</param>
        public void ShowAlert(string title, string message, string button) =>
                //Device.BeginInvokeOnMainThread(() =>
                MainPage.DisplayAlert(title, message, button);

        /// <summary>
        /// 显示警告。
        /// </summary>
        /// <param name="title">标题。</param>
        /// <param name="message">信息。</param>
        /// <param name="button1">按钮一文字。</param>
        /// <param name="button2">按钮二文字。</param>
        public Task<bool> ShowAlert(string title, string message,
            string button1, string button2) =>
            MainPage.DisplayAlert(title, message, button1, button2);

        public async Task<string> ShowAlert(string title, string cancel, string choice1, string choice2,
            string choice3, string choice4)
        {
            return await MainPage.DisplayActionSheet(title, cancel, choice1, choice2,
                choice3, choice4);
        }
    }
}
